﻿#pragma once

#include "Containers/Containers.h"
#include "Math/Rect.h"
#include "Font/TextTexturePool.h"

class RTexture2D;
class RFont;

struct WHENGINE_API SFreeTypeGlyph : public std::enable_shared_from_this<SFreeTypeGlyph>
{
public:    
    SFreeTypeGlyph(void * InGlyph)
    {
        Glyph=InGlyph;
    }

    ~SFreeTypeGlyph();

    SFreeTypeGlyph(SFreeTypeGlyph& Other)=delete;
    SFreeTypeGlyph& operator =(SFreeTypeGlyph& Other)=delete;

    SFreeTypeGlyph(SFreeTypeGlyph&& Other)
    {
        Glyph=Other.Glyph;
        Other.Glyph=nullptr;
    }

    SFreeTypeGlyph& operator =(SFreeTypeGlyph&& Other)
    {
        Glyph=Other.Glyph;
        Other.Glyph=nullptr;

        return *this;
    }   

    //FreeType的字形，类型为FT_Glyph
    void * Glyph=nullptr;


    char32_t CodePoint=0; //unicode code point
    uint32_t FontSize=0; //font size
    TWeakObjectPtr<RFont> Font; //font

    //字符占据的空间，包含字符周围的空白区域
    float AdvanceX=0;
    float AdvanceY=0; 
    
    //文字图片的包围盒，Y轴向上，原点在文字左下角
    SRect Box;

    //can be null if glyph is space
    TOptional<SCharTexture> LoadTexture();
protected:
    bool bTextureLoaded=false;
    TOptional<SCharTexture> Texture; //texture that store glyph image
};